package org.jivesoftware.smackx.provider;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.xmlpull.v1.XmlPullParser;

public abstract class EmbeddedExtensionProvider
  implements PacketExtensionProvider
{
  protected abstract PacketExtension createReturnExtension(String paramString1, String paramString2, Map<String, String> paramMap, List<? extends PacketExtension> paramList);

  public final PacketExtension parseExtension(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    String str1 = paramXmlPullParser.getNamespace();
    String str2 = paramXmlPullParser.getName();
    HashMap localHashMap = new HashMap();
    int i = 0;
    while (true)
    {
      if (i >= paramXmlPullParser.getAttributeCount())
      {
        ArrayList localArrayList = new ArrayList();
        do
          if (paramXmlPullParser.next() == 2)
            localArrayList.add(PacketParserUtils.parsePacketExtension(paramXmlPullParser.getName(), paramXmlPullParser.getNamespace(), paramXmlPullParser));
        while (!(str2.equals(paramXmlPullParser.getName())));
        return createReturnExtension(str2, str1, localHashMap, localArrayList);
      }
      localHashMap.put(paramXmlPullParser.getAttributeName(i), paramXmlPullParser.getAttributeValue(i));
      ++i;
    }
  }
}